/* Copyright [2023] <gyl> */
#pragma once

#include <vector>
#include "common/rc.h"
#include "sql/operator/physical_operator.h"
#include "storage/record/record_manager.h"

class Table;

/**
 * @brief 聚合物理算子
 * @ingroup PhysicalOperator
 */
class AggrPhysicalOperator : public PhysicalOperator {
 public:
  explicit AggrPhysicalOperator(std::vector<AggregateUnit> aggregations)
      : aggregations_(aggregations) {}

  virtual ~AggrPhysicalOperator() = default;

  PhysicalOperatorType type() const override {
    return PhysicalOperatorType::AGGR;
  }

  RC open(Trx *trx) override;
  RC next() override;
  RC close() override;

  Tuple *current_tuple() override;

 private:
  std::vector<AggregateUnit> aggregations_;
  RowTuple tuple_;
};
